import os

from flask import Config
from redis import Redis

from app.common.utils import singleton


@singleton
class Env:
    def __init__(self):
        self.cfg_dir = os.path.abspath(os.path.dirname(__file__) + '/../config')
        self.cfg_file = os.environ.get('TD_CONFIG_FILE') or self.cfg_dir + '/td.cfg'
        self.cfg = Config(self.cfg_dir)
        self.cfg.from_pyfile(self.cfg_file)

        self.redis_url = self.cfg.get('REDIS_URL')
        self.redis_client = Redis.from_url(self.redis_url, decode_responses=True)

        self.mongo_url = self.cfg.get('MONGO_DB_URL')
        self.db_name = self.cfg.get('MONGO_DB_NAME')

        self.log_level = self.cfg.get('LOG_LEVEL', 'DEBUG')

        self.hunter_url = self.cfg.get('HUNTER_URL')
        self.dll = None
        self.workers = {}
